<template>
  <div class="out-info">
    <div class="box">
      <div>
        <div class="flex-b">
          <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" class="input">
            <el-form-item>
              <el-input v-model="queryParams.name" style="width:340px" prefix-icon="el-icon-search" placeholder="请输入寄养类型名称或寄养项目/规格或条形码" clearable
                @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" class="btn" size="mini" @click="handleQuery">查询</el-button>
              <el-button type="warning" class="btn" size="mini" @click="jumpTo">新增寄养类型</el-button>
            </el-form-item>
          </el-form>
        </div>
        <div>
          <el-table v-loading="loading" :data="outList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="图片" align="center" prop="url" >
              <template slot-scope="scope">
                <img :src="scope.row.url" style="width:50%" alt="">
              </template>
            </el-table-column>
            <el-table-column label="寄养类型" align="center" prop="name" />
            <el-table-column label="寄养项目/规格" align="center" prop="no" />
            <el-table-column label="条形码" align="center" prop="price" />
            <el-table-column label="日单价" align="center" prop="num" />
            <el-table-column label="日单会员价" align="center" prop="addNum" />
            <el-table-column label="会员卡折扣" align="center" prop="operUser" />
            <el-table-column label="附含商品" align="center" prop="timeSting" /> 
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <!-- <el-button size="mini" type="text" icon="el-icon-document" @click="handleUpdate(scope.row)"
                  v-hasPermi="['pet:out:edit']">详情</el-button>
                <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                  v-hasPermi="['pet:out:remove']">撤销</el-button> -->
              </template>
            </el-table-column>
          </el-table>
          <div class="flex-b flex-a">
            <el-dropdown class="dropdown" placement="bottom" @command="handleCommand" style="top:20px;" >
                  <span class="el-dropdown-link">
                    批量操作<i class="el-icon-arrow-down el-icon--right"></i>
                  </span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item v-for="item in operationList" :key="item.value" :command="item.value">{{
                      item.label
                    }}</el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
          <pagination :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList" />
          </div>
        </div>
      </div>
    </div>
     <!-- 详情对话框 -->
     <el-dialog title="出库详情" :visible.sync="open" width="1000px" append-to-body>
      <div class="in-detail">
        <div>出库单号：{{ info.no }}</div>
        <div>出库类型：{{ info.type }}</div>
        <div>出库时间：{{ info.rkDate }}</div>
        <div>出库备注：{{ info.remark }}</div>
      </div>
      <el-table v-loading="loading" :data="outDetailList">
        <el-table-column label="商品图片" align="center" prop="url">
          <template slot-scope="scope">
            <img :src="scope.row.url" alt="">
          </template>
        </el-table-column>
        <el-table-column label="商品名称" align="center" prop="name" />
        <el-table-column label="条形码" align="center" prop="no" />
        <el-table-column label="规格型号" align="center" prop="spetModel" />
        <el-table-column label="出库数量" align="center" prop="num" />
        <el-table-column label="出库单价" align="center" prop="price" />
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import { listOut, getOut, delOut, addOut, updateOut,listOutDetail } from "@/api/pet/out";
export default {
  name: "Out",
  data() {
    return {
      operationList: [
        {
          label: '修改日单价',
          value: '1'
        },
        {
          label: '修改日单会员价',
          value: '2'
        },
        {
          label: '修改会员卡折扣',
          value: '3'
        },
        {
          label: '删除',
          value: '4'
        },
      ],
      outDetailList:[],
      info:{},
      open:false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商品出库表格数据
      outList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        prodNo: null,
        outNo: null,
        outType: null,
        operUser: null,
        outNum: null,
        outPice: null,
        outRemark: null,
        updateUser: null,
        createUser: null,
        time: []
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询商品出库列表 */
    getList() {
      this.loading = true;
      listOut(this.queryParams).then(response => {
        this.outList = response.rows;
        this.assNum=response.assNum
        this.total = response.total;
        this.loading = false;
      });
    },
    // 下拉菜单
    handleCommand(command) {
      if (command == 10) {
        if (this.ids.length < 1) {
          this.$message({
            message: '至少勾选一个',
            type: 'warning'
          });
        }else{
          this.handleDelete(command)
        }
      }
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        prodNo: null,
        outNo: null,
        outType: null,
        operUser: null,
        outNum: null,
        outPice: null,
        outRemark: null,
        updateUser: null,
        updateTime: null,
        createUser: null,
        createTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.queryParams.beginTime  = this.queryParams.time[0]
      this.queryParams.endTime  = this.queryParams.time[1]
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      listOutDetail({id}).then(response => {
        this.info = response.data;
        this.outDetailList= response.data.list;
        this.open = true;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOut(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOut(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除商品出库编号为"' + ids + '"的数据项？').then(function () {
        return delOut(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    //新增寄养类型
    jumpTo() {
      this.$router.push({ path: '/stock/outbound', query: {} })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('pet/out/export', {
        ...this.queryParams
      }, `out_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style lang="scss" scoped>

.in-detail {
  background-color: #f9f9f9;
  border-radius: 8px;
  border: 1px solid #ecebed;
  padding: 10px;
  display: flex;
  flex-wrap: wrap;

  div {
    display: inline-block;
    width: calc(33.3% - 20px);
    padding: 8px 10px;
    line-height: 24px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
</style>
